package cn.com.ccxe.core.entity;


import com.sleepycat.persist.model.PrimaryKey;

public class Article {

	@PrimaryKey
	private String 	url;
	private String 	title;
	private String 	content;
	private int		moduleId; 
	private int 	hash;
	private String 	releaseDate; 	//文章发布日期，格式为：yyyy-MM-dd hh:mm 
	
	
	public Article(){}
	public Article(String url) {
		this.url = url;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("URL:").append(url).append(",");
		sb.append("Title:").append(title).append(",");
		if(content != null) {
			sb.append("Content-length:").append(content.length()).append("");
		} else {
			sb.append("Content-length:NULL;");
		}
		sb.append(",ReleaseDate:").append(releaseDate);
		return sb.toString();
	}
	
	@Override
	public int hashCode() {
		if(hash != 0) {
			return hash;
		}
		int result = 17;
		result = 31 * result + moduleId;
		result = 31 * result + url.hashCode();
		result = 31 * result + title.hashCode();
		if(content != null) {
			result = 31 * result + content.length();
		}
		hash = result;
		return hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Article) {
			Article a = (Article) obj;
			return  a.getModuleId() == this.moduleId
					&& a.getUrl().equals(this.url) 
					&& a.getTitle().equals(this.title)
					&& a.getContent().length() 
									== this.content.length() 
									? true 
									: false;
		}
		return false;
	}
	
	/**              GET METHOD             */
	public int getModuleId() { return moduleId; }
	public String getUrl() {return url;}
	public String getTitle() {return title;}
	public String getContent() {return content;}
	public String getReleaseDate() {return releaseDate == null ? "" : releaseDate;}
	public long getReleaseDate2Long() {	
		if(releaseDate == null || releaseDate.length() <= 0) {
			return 0;
		}
		try {
			return Long.valueOf(releaseDate);
		} catch (NumberFormatException e) {
			return 0;
		}
	}
	
	/**              SET METHOD             */
	public void setTitle(String title) {this.title = title;}
	public void setContent(String content) {this.content = content;}
	public void setUrl(String url) {this.url = url;}
	public void setModuleId(int moduleId) { this.moduleId = moduleId; }
	public void setReleaseDate(String releaseDate) {this.releaseDate = releaseDate;}
	
	
	
}
